package 双指针;


/**
 * https://leetcode.cn/problems/container-with-most-water/
 *
 * 题解：https://mp.weixin.qq.com/s?__biz=MzAxODQxMDM0Mw==&mid=2247493099&idx=1&sn=d85dd10af42958648485bd92f037a5fb&chksm=9bd41be3aca392f58ddac25a43850654c30d00f40ea87702cf7a2c543f3747659fa7c47c4b1f&scene=178&cur_album_id=2165005132189564928#rd
 */
public class _11_盛最多水的容器 {

    public int maxArea(int[] height) {
        if(height == null || height.length == 0) return 0;

        int left = 0;
        int right = height.length - 1;

        int area = 0;

        while (left < right) {
            int h = Math.min(height[left],height[right]);

            area = Math.max(area,h * (right - left));

            if(height[left] < height[right]) {
                left++;
            }else {
                right--;
            }
        }

        return area;
    }
}
